package com.apes.hr.area.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.frame.model.Dept;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * @program:
 * @description:
 * @author: lws
 * @create: 2023/2/20 10:13
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = DeptAreaLogger.CONST_TABLE_NAME)
public class DeptAreaLogger extends BaseModel {
    public static final String CONST_TABLE_NAME = "dept_area_logger";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "门店区域日志编码", padding = 8)
    @Comment("日志编码")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id", referencedColumnName = "id")
    @Comment("门店")
    private Dept dept;

    @Name
    @Column(name = "dept_area_id", nullable = false, length = 120)
    @Comment("门店区域编码")
    private String deptAreaId;

    @Name
    @Column(name = "dept_area_name", nullable = false, length = 120)
    @Comment("门店区域名称")
    private String deptAreaName;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "change_date")
    @Comment("变动时间")
    private Date changeDate;

    @States(name = "状态", values = {
            @State(id = "create", name = "创建"),
            @State(id = "end", name = "终止")
    })
    @Column(name = "state", length = 10, nullable = false)
    private String state;
}
